package com.nhh.v.utils;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;

/**
 * Created by ywp on 2018/9/4.
 */
public class FormatterUtil {

    //默认3位
    private static final ThreadLocal<NumberFormat> numberFormatterHolder = ThreadLocal.withInitial(NumberFormat::getInstance);

    //2位
    private static final ThreadLocal<DecimalFormat> decimalFormatterHolder = ThreadLocal.withInitial(() -> new DecimalFormat("#,###.00"));

    private static final ThreadLocal<DateFormat> dayFormatterHolder = ThreadLocal.withInitial(() -> new SimpleDateFormat("ddHHmmss"));

    private static final ThreadLocal<DateFormat> monthFormatterHolder = ThreadLocal.withInitial(() -> new SimpleDateFormat("Ym"));

    public static String format(Object number) {
        return numberFormatterHolder.get().format(number);
    }

    public static String dayFormat(Object time) {
        return dayFormatterHolder.get().format(time);
    }

    public static String monthFormat(Object time) {
        return monthFormatterHolder.get().format(time);
    }

    public static String format(BigDecimal bigDecimal) {
        return decimalFormatterHolder.get().format(bigDecimal);
    }
}
